<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ModelsAddQueue implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    use TraitQueue;

    protected $class;
    protected $data;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($class, $data)
    {
        $this->class = $class;
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $class  = $this->class;
        $model  = new $class;
        foreach ($this->data as $key => $val) {
            $model->$key = $val;
        }
        $model->save();
    }
}
